<template>
	<view class="tabbar-box">
		<view class="menu-list">
			<view class="item" :style="{ color: selIdx == index ? hoverColor : color }" v-for="(item, index) in list"
				@click="click(index)" :key="index">
				<view :class="{
						big: index == bigIdx
					}">
					<view class="icon-box">
						<image mode="aspectFit" :src="selIdx == index ? item.selectedIconPath : item.iconPath"></image>
					</view>
				</view>
				<text v-if="item.text">{{ item.text }}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Array,
				default: [{
						"isTabBar": true, //是tabBar页面
						"pagePath": "/pages/home/home",
						"iconPath": "/static/images/tabBar1.png",
						"selectedIconPath": "/static/images/active1.png",
						"text": "首页"
					},
					{
						"isTabBar": true,
						"pagePath": "/pages/product/product",
						"iconPath": "/static/images/tabBar2.png",
						"selectedIconPath": "/static/images/active2.png",
						"text": "商品"
					},
					{
						"isTabBar": true,
						"pagePath": "/pages/collect/collect",
						"iconPath": "/static/images/tabBar3.png",
						"selectedIconPath": "/static/images/active3.png",
						"text": "收藏"
					},
					{
						"isTabBar": true,
						"pagePath": "/pages/order/order",
						"iconPath": "/static/images/tabBar4.png",
						"selectedIconPath": "/static/images/active4.png",
						"text": "订单"
					},
					{
						"isTabBar": true,
						"pagePath": "/pages/my/my",
						"iconPath": "/static/images/tabBar5.png",
						"selectedIconPath": "/static/images/active5.png",
						"text": "我的"
					}
				]
			}, //菜单配置
			defaultSel: {
				type: Number,
				default: 0
			}, //默认选中菜单
			hoverColor: {
				type: String,
				default: "#000000"
			}, //选中颜色
			color: {
				type: String,
				default: "#666666"
			}, //默认颜色
			bigIdx: {
				type: Number,
				default: -1
			} //大图标显示菜单-1为未开启
		},
		data() {
			return {
				selIdx: -1
			};
		},
		mounted() {
			this.selIdx = this.defaultSel;
		},
		methods: {
			click(idx) {
				this.selIdx = idx;
				if (this.list[idx].pagePath) {
					uni.redirectTo({
						url: this.list[idx].pagePath
					});
				}
				this.$emit("clickTab", idx);
			}
		}
	};
</script>

<style lang="scss">
	.tabbar-box {
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 9;
		width: 100%;
		height: 100rpx;
		background-color: #ffffff;
		display: flex;
		align-items: center;
		box-shadow: 0rpx 0rpx 12rpx rgba(0, 0, 0, 0.2);
	}

	.menu-list {
		display: flex;
		justify-content: space-around;
		text-align: center;
		font-size: 28rpx;
		width: 100%;
		height: 100rpx;
		align-items: center;

		.item {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;
			height: 100rpx;
			box-sizing: border-box;

			height: 80rpx;
			font-size: 22rpx;
			color: #757575;

			image {
				width: 40rpx;
				height: 40rpx;
			}

			.icon-box {
				width: 40rpx;
				height: 40rpx;
				text-align: center;
				display: flex;
				justify-content: space-around;
				position: relative;
			}

			.big {
				.icon-box {
					image {
						width: 120rpx;
						height: 120rpx;
						position: absolute;
						top: -40rpx;
						background-color: #ffffff;
						border-radius: 50%;
					}
				}
			}
		}
	}
</style>